<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>食谱管理</title>
	<link rel="stylesheet" href="../css/common2.css">

	<style>
		.two {
			width: 15%;
		}

		.three {
			width: 120px !important;
		}

		.two .photo {
			width: 50px;
			height: 50px;
		}

		.search_img {
			position: absolute;
			margin-top: 1px;
			right: 3%;
		}

		td>div {
			white-space: pre-wrap;
			padding-left: 5px;
		}
	</style>
</head>

<body>
	<div id="vue-root" style="margin-top: 30px;">
		<div class="add action-buttons" v-if="able.add">
			<a href="basis_cookbook_item.html" style="color: white">添加食谱</a>
		</div>
		<div class="refresh action-buttons" onclick="location.reload()">刷新</div>

		<div class="table">
			<table class="table_top">
				<thead>
					<tr>
						<th style="max-width: 50px">
							<input type="checkbox" class="check-box" v-model="all">
						</th>
						<th style="max-width: 50px">序号</th>
						<th class="one">星期</th>
						<th class="two">早餐</th>
						<th class="two">早加餐</th>
						<th class="two">午餐</th>
						<th class="two">午加餐</th>
						<th class="two">晚餐</th>
						<th class="three">编辑/删除</th>
					</tr>
				</thead>
				<tbody id="list">
					<tr v-for="(cookbook,index) in list" :key="cookbook.id">
						<td>
							<input type="checkbox" class="check-box" v-model="cookbook.checked">
						</td>
						<td><span v-text="index+1"></span></td>
						<td class="one" v-text="dayList[cookbook.day]"></td>
						<td class="two">
							<img v-if="cookbook.breakfastPic" :src="getImg(cookbook.breakfastPic)" class="photo"
								@click="bigImg(cookbook.breakfastPic)">
							<div v-text="cookbook.breakfast"></div>
						</td>
						<td class="two">
							<img v-if="cookbook.breakfastPlusPic" :src="getImg(cookbook.breakfastPlusPic)" class="photo"
								@click="bigImg(cookbook.breakfastPlusPic)">
							<div v-text="cookbook.breakfastPlus"></div>
						</td>
						<td class="two">
							<img v-if="cookbook.lunchPic" :src="getImg(cookbook.lunchPic)" class="photo"
								@click="bigImg(cookbook.lunchPic)">
							<div v-text="cookbook.lunch"></div>
						</td>
						<td class="two">
							<img v-if="cookbook.lunchPlusPic" :src="getImg(cookbook.lunchPlusPic)" class="photo"
								@click="bigImg(cookbook.lunchPlusPic)">
							<div v-text="cookbook.lunchPlus"></div>
						</td>
						<td class="two">
							<img v-if="cookbook.dinnerPic" :src="getImg(cookbook.dinnerPic)" class="photo"
								@click="bigImg(cookbook.dinnerPic)">
							<div v-text="cookbook.dinner"></div>
						</td>
						<td class="three" style="border-left: none; margin-top: 1px;">
							<div class="option">
								<div v-if="able.edit" class="edit-icon option-icon"
									style="position: absolute; left: 20%; top: 30%;">
									<a :href="'basis_cookbook_item.html?id='+cookbook.id">
										<img class="img" src="../image/edit.png" height="20" width="20"
											onmouseover="this.src='../image/edit_light.png'"
											onmouseout="this.src='../image/edit.png'" />
									</a>
								</div>
								<div v-if="able.del" class="delete-icon option-icon" @click="del([cookbook.id])"
									style="right: 20%; top:30%;position: absolute;">
									<img class="img" src="../image/delete.png" height="20" width="20"
										onmouseover="this.src='../image/delete_light.png'"
										onmouseout="this.src='../image/delete.png'" />
								</div>
							</div>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<br>
		<div class="delete" @click="batchDelete" v-if="able.del">批量删除</div>
		<ul class="pagination" v-if="pages>1">
			<li>
				<a v-if="pageNum!=1" @click="pageNum=1">«</a>
				<a class="pages-jump" v-if="pageNum!=1" @click="pageNum--">‹</a>
				<a v-text="pageNum"></a>
				<a class="pages-jump" v-if="pageNum!=pages" @click="pageNum++">›</a>
				<a v-if="pageNum!=pages" @click="pageNum=pages">»</a>
			</li>
		</ul>
		<div v-if="bigimg">
			<div class="img_layer"></div>
			<img :src="bigimg?big_src:''" class="big_Img" @click="bigimg=false">
		</div>
	</div>

	<script src="/scriptZIP/qs.min.js"></script>
	<script src="/scriptZIP/vue.min.js"></script>
	<script src="/scriptZIP/axios.min.js"></script>

	<script src="../js/common.js"></script>
	<script src="../js/list.js"></script>
	<script src="/js/auth_util.js"></script>

	<script>

		var dayList = '日一二三四五六'.split('').map(function (it) {
			return '星期' + it;
		});

		var app = new Vue(merge({
			data: {
				dayList: dayList,
				days: dayList.map(function (it, index) {
					return { id: index, name: it };
				}),
				urls: {
					del: '/pc/cookbook/del'
				}
			},
			created: function () {
				this.schoolId = top_params().id;
				if (!this.schoolId) throw 'no school id';
				this.urls.list = '/pc/cookbook/list/' + this.schoolId;
				this.getData();
				abled('cookbook', this);
			},
			methods: {
				getImg: function (pic) {
					if (!pic) return null;
					return '/static/' + this.schoolId + '/cookbook/' + pic;
				},
				bigImg: function (pic) {
					this.big_src = this.getImg(pic);
					this.bigimg = true;
				}
			}
		}));
	</script>


</body>

</html>